home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
mscfunct
/
crt_line.c
< prev
next >
Wrap
Text File
|
1987-05-11
|
903b
|
36 lines
/* draw a line in graphics mode on color monitor
*/
/* simple sign function */
#define sign(a) ( (a < 0) ? -1.0 : 1.0 )
void crt_line(x1,y1,x2,y2,color) int x1, y1, x2, y2, color;
{
float x, y, xinc, yinc;
int xp, yp;
if( x1 == x2 ){ /* delta x = 0 ? */
xinc = 0.; yinc = sign( y2-y1 );
}
else if( y1 == y2 ){ /* delta y = 0 ? */
yinc = 0.; xinc = sign( x2-x1 );
}
else { /* assume delta x > delta y */
xinc = 1.;
yinc = ( y2 - y1 ) / (float)abs( x2 - x1 );
if( abs( y1 - y2 ) > abs( x1 - x2 ) ){ /* check */
yinc = 1.;
xinc = ( x2 - x1 ) / (float)abs( y2 - y1 );
}
}
/* loop, incrementing x & y until end point is reached */
for( x = xp = x1, y = yp = y1; !( xp == x2 && yp == y2 );
x += xinc, y += yinc, xp = x + 0.5, yp = y + 0.5 )
crt_write_pixel( xp, yp, color );
}